﻿@model Think9.Models.RuleListEntity
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<form class="layui-form " lay-filter="formUser">
    <input style="display: none" id="_id" value="@ViewBag.RuleID">
    <div class="layui-form-item">
        <label class="layui-form-label  required">名 称</label>
        <div class="layui-inline">
            <input type="text" name="RuleName" id="RuleName" placeholder="请输入名称" autocomplete="off" class="layui-input" lay-verify="required" value="@ViewBag.RuleName">
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="edit">编辑</button>
        </div>
    </div>
</form>

<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script src="~/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="~/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;

        var $ = layui.$;

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysTable/RuleAuto/GetList/" + $("#_id").val(),
            page: false,
            defaultToolbar: [{ title: '刷新', layEvent: 'refresh', icon: 'layui-icon-refresh' }],
            toolbar: "#toolbarTpl",
            cols: [[
                { field: "AutoShow", title: "AutoShow", sort: true },
                { title: "操作", width: 80, align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                /* $('.layui-table .layui-table-cell > span').css({ 'font-weight': 'bold' });//表头字体样式*/
                /*$('th').css({'background-color': '#5792c6', 'color': '#fff','font-weight':'bold'}) 表头的样式 */
                $('th').hide();//表头隐藏的样式
                /* $('.layui-table-page').css('margin-top', '40px');//页码部分的高度调整*/
                console.log(res, curr, count);
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
                case "refresh":
                    refresh();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "del":
                    del(data.AutoOrder);
                    break;
            }
        });

        form.on("submit(edit)", function (data) {
            exUtils.ajax("/SysTable/RuleList/UpNameByID", "post", { id: $("#_id").val(), name: $("#RuleName").val() }, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    $(window.parent.document).find('#search').click();//刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        function add() {
            exLayer.openMiddle("添加", "/SysTable/RuleAuto/AddItem?rid=" + $("#_id").val(), '800px', '400px', null, null);
        }

        function refresh() {
            table.reload('tableId', {})
        }

        function del(id) {
            exLayer.confirm("确定要删除吗？", function () {
                exUtils.ajax("/SysTable/RuleAuto/Delete", "get", { id: id }, true).done(function (response) {
                    ThisTable.reload({
                    });
                    exUtils.tableSuccessMsg(response.message);
                    /* $(".layui-laypage-btn")[0].click();*/
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }
    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <div class="layui-inline">
        <button class="layui-btn  layui-btn-normal layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>添加</button>
    </div>
    <div class="layui-inline">
        <span class="layui-word-aux"><i class="fa fa-angle-double-left"></i>自动编号由固定字符、日期、序号等组成 点击【添加】按钮逐项添加</span>
    </div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" id="del">删除</a>
</script>